// Trade-Policy Dynamics: Evidence from 60 Years of U.S.-China Trade
// Alessandria,  Khan, Khederlarian, Ruhl, and Steinberg

// inputs:	Raw data/Feenstra
//			uncodes_uscodes_wbcodes.dta

// outputs:	SITC2-TSUSA_concordance.dta
//			uncodes_unique_wbcodes.dta

clear all 
global dir_raw "../01 Raw data/"
global dir_int "../20 Intermediate files/"

////////////////////////////////////////////////////////////////////////////////
// Concordance between TSUSA and SITC
// We back this concordance out of the data files from Feenstra.
{
	// 1972--1988
	use "${dir_raw}Feenstra/imp74/imp74.dta", clear
	forvalues x = 75/88 {
		append using "${dir_raw}/Feenstra/imp`x'/imp`x'.dta"
	}
	gen year = yr+1900
	drop yr
	collapse (first) sitc2 (sum) cusvalue, by(year tsusa)
	save "${dir_int}SITC2-TSUSA_concordance", replace
}

////////////////////////////////////////////////////////////////////////////////
// Unique uncodes
{
	use "${dir_raw}uncodes_uscodes_wbcodes.dta"

	drop uscode uscountry
	replace wbcode="BLX" if uncode==530560 // Belgium-Luxemburg

	duplicates drop

	drop if wbcode==""

	drop if uncode==117100 & wbcode!="ZAF" // south africa
	drop if uncode==164500 & wbcode!="MDG" // madagascar
	drop if uncode==166240 & wbcode!="GNB" // Guinea-Bissau

	drop if uncode==353880 & wbcode!="JAM" // Jamaica
	drop if uncode==355320 & wbcode!="ANT" // Netherlands Antilles
	drop if uncode==356580 & wbcode!="KNA" // St. Kitts and Nives
	drop if uncode==413760 & wbcode!="ISR" // Israel
	drop if uncode==532500 & wbcode!="FRA" // France
	drop if uncode==722960 & wbcode!="KIR" // Kiribati
	drop if uncode==728882 & wbcode!="WSM" // Samoa

	// The following are dubious
	drop if uncode==450000
	drop if uncode==368960
	drop if uncode==166380

	tostring uncode, replace

	save "${dir_int}uncodes_unique_wbcodes.dta", replace
}